package demo.starter;

import demo.first.MyFirstMapper;
import demo.first.MyFirstReducer;
import demo.mapper.MultiFileCountMapper;
import demo.reducer.MultiFileCountReducer;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MultiFileCountStarter {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        if (args.length != 2) {
            System.out.println("输入2个参数,1=input 2=output");
        }

        Job job = new Job();
        job.setJarByClass(MultiFileCountStarter.class);
        job.setJobName("============ MultiFileCountStarter Job ==============");

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(MultiFileCountMapper.class);
        job.setReducerClass(MultiFileCountReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

